package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.Quotationdetails;
import cn.gson.boot.model.pojos.Role;
import cn.gson.boot.model.pojos.User;
import cn.gson.boot.model.pojos.UserLogin;
import cn.gson.boot.model.service.QuotationDetailsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/quotationDetails")
public class QuotationDetailsController {
    @Autowired
    QuotationDetailsService quotationDetailsService;

    /**
     * 报价明细查询
     * @param search
     * @return
     */
    @RequestMapping("/quotationDetails-list")
    @ResponseBody
    public List<Quotationdetails> selectProduct(String search, HttpSession session){
        User us = (User)session.getAttribute("user");
        List<UserLogin> users = (List<UserLogin>)session.getAttribute("users");
        List<Role> roles = users.get(0).getRoleListss();
        List<String> jueNameList = new ArrayList<>();
        for(int i=0;i<roles.size();i++){
            jueNameList.add(roles.get(i).getJueName());
        }
        String empName = null;
        if(jueNameList.indexOf("boss")>-1 ||jueNameList.indexOf("销售经理")>-1  ){
            empName = null;
        }else{
            empName = us.getEmpName();
        }
        return quotationDetailsService.selectQuotationDetails(search,empName);
    }

}
